package com.gxa.p2p.service.impl;

import com.gxa.p2p.mapper.VerifiedInfoMapper;
import com.gxa.p2p.pojo.VerifiedInfo;
import com.gxa.p2p.service.VerifiedInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("verifiedInfoService")
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS, isolation = Isolation.DEFAULT)
public class VerifiedInfoServiceImpl implements VerifiedInfoService {

    @Resource
    VerifiedInfoMapper verifiedInfoMapper;

    /**
     * 带条件,且条件含有非空判断的全查询
     * @param map
     * @return list
     */
    @Override
    public List<VerifiedInfo> findAll(Map<String,Object> map) {
        int page = ((Integer) map.get("page") - 1) * (Integer) map.get("limit");
        map.put("page",page);
        return verifiedInfoMapper.findAll(map);
    }

    /**
     * 计算带条件的数据总数
     * @param map
     * @return Integer
     */
    @Override
    public Integer dataSum(Map<String,Object> map) {
        return verifiedInfoMapper.dataSum(map);
    }

    /**
     * 添加审核信息
     * @param verifiedInfo
     * @return Integer 修改的行数
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED, rollbackFor = {Throwable.class})
    public Integer updateReviewStatus(VerifiedInfo verifiedInfo) {
        return verifiedInfoMapper.updateReviewStatus(verifiedInfo);
    }
    /**
     * 查询身份证审核状态
     * @param
     * @param
     * @return
     */
    @Override
    public VerifiedInfo findByReviewStatus(Integer userId) {

        return verifiedInfoMapper.findByReviewStatus(userId);
    }

    @Override
    public Boolean saveVer(VerifiedInfo verifiedInfo) {
        return verifiedInfoMapper.insertSelective(verifiedInfo) > 0;
    }

    @Override
    public VerifiedInfo findUserInfo(Integer id) {
        return verifiedInfoMapper.selectByUser(id);
    }
}
